package com.itboye.ihomebank.home;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.adapter.MyFaBuAdapter02;
import com.itboye.ihomebank.adapter.WodeFangyYuanAdapter;
import com.itboye.ihomebank.base.BaseOtherActivity;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.bean.WoDeFangYuanBean;
import com.itboye.ihomebank.constants.SPContants;
import com.itboye.ihomebank.custom.XListView;
import com.itboye.ihomebank.presenter.HousePresenter;
import com.itboye.ihomebank.util.SPUtils;
/**
 * 房源管理
 *
 */
public class ActivityFangYuanGuanLi extends BaseOtherActivity implements Observer{
	private ImageView imgEmpty, close_icon;
	private TextView add_shap_title_tv;
	private XListView xlistView;
	HousePresenter housePresenter;
	private String uid;
	private List<WoDeFangYuanBean> arrayHouse;
	MyFaBuAdapter02 adapter;
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.close_icon:
			finish();
			break;

		default:
			break;
		}

	}

	@Override
	protected int layout_id() {
		// TODO Auto-generated method stub
		return R.layout.activity_fang_yuan_guanli;
	}

	@Override
	protected void onInitController() {
		// TODO Auto-generated method stub

	}

	@Override
	protected void onInit() {
		add_shap_title_tv.setText("房源管理");
		xlistView.setPullRefreshEnable(false);
		
		uid = SPUtils.get(this, null, SPContants.USER_ID, "") + "";
		housePresenter=new HousePresenter(this);
		housePresenter.getWoDeFaBu(uid);
		
		arrayHouse = new ArrayList<WoDeFangYuanBean>();
		adapter = new MyFaBuAdapter02(this, arrayHouse,
				R.layout.item_wodefangyuan02);
		xlistView.setAdapter(adapter);
	}

	@Override
	protected void onReadIntent(Bundle bundle) {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(Observable observable, Object data) {
		ResultEntity entity = handlerError(data);
		if (entity != null) {
			if (entity.getEventType() == HousePresenter.woDeFaBuList_success) {
				List<WoDeFangYuanBean> woDeFangYuanBeans = (List<WoDeFangYuanBean>) entity
						.getData();
				if (woDeFangYuanBeans != null) {
					if (woDeFangYuanBeans.size() <= 0) {
						imgEmpty.setVisibility(View.VISIBLE);
					}else{
						imgEmpty.setVisibility(View.GONE);
					}
				}if (woDeFangYuanBeans.size() <= 0) {
					imgEmpty.setVisibility(View.VISIBLE);
				}
				arrayHouse.addAll(woDeFangYuanBeans);
				adapter.notifyDataSetChanged();
			} else if (entity.getEventType() == HousePresenter.woDeFaBuList_success) {

			}
		}
		
	}

}
